import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { FormatResponseInterceptor } from './middleware/format/format-response.interceptor';
import { InvokeRecordInterceptor } from './middleware/format/invoke-record.interceptor';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { UnloginFilter } from './middleware/exception/unlogin.filter';
import { CustomExceptionFilter } from './middleware/exception/custom-exception.filter';
async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  app.useGlobalPipes(new ValidationPipe());
  app.useGlobalInterceptors(new FormatResponseInterceptor());
  app.useGlobalInterceptors(new InvokeRecordInterceptor());
  app.useGlobalFilters(new UnloginFilter());
  app.useGlobalFilters(new CustomExceptionFilter());
  // app.enableCors(); // 跨域
  const configService = app.get(ConfigService);
  const config = new DocumentBuilder()
    .setTitle('会议室预定系统')
    .setDescription('Nest 单体项目')
    .setVersion('1.0.0')
    .addBearerAuth({
      type: 'http',
      description: '基于 jwt 的认证',
    })
    .build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('swagger-doc', app, document);
  await app.listen(configService.get('nest_server_port'));
  // await app.listen(3000);
}
bootstrap();
